package com.wac.data.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wac.data.entity.Criticism;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author beta
 * @since 2023-03-16
 */
public interface CriticismMapper extends BaseMapper<Criticism> {

	//获取某用户的番评数量
	@Select("select count(*) from criticism where user_id = #{userId}")
	int getCriticismNum(String userId);

	//分页查询该番剧下的所有番评 时间倒序 时间正序
	@Select("select criticism.*,`user`.`name`,`user`.head_url,l.likeNum " + "from criticism left join `user` on  `user`.id = criticism.user_id,(select criticism.id,count(entity_id) as likeNum from criticism " + "left join `like` on `like`.entity_id = criticism.id group by criticism.id) as l " + "where criticism.bangumi_id = #{id} and criticism.id = l.id order by time desc")
	Page<Criticism> selectByBangumiDesc(Page page, String id);

	@Select("select criticism.*,`user`.`name`,`user`.head_url,l.likeNum " + "from criticism left join `user` on  `user`.id = criticism.user_id,(select criticism.id,count(entity_id) as likeNum from criticism " + "left join `like` on `like`.entity_id = criticism.id group by criticism.id) as l" + "where criticism.bangumi_id = #{id} and criticism.id = l.id order by time asc")
	Page<Criticism> selectByBangumiAsc(Page page, String id);

	//分页查询某用户的所有番评 时间倒序
	@Select("select criticism.*,`user`.`name`,`user`.head_url from criticism " + "left join `user` on `user`.id = criticism.user_id " + "where criticism.user_id = #{userId} order by time desc")
	Page<Criticism> selectByUserId(Page page, String userId);


}
